/*
Replication master file: Childbirth and Firm Performance
=============================================================

Runs all do-files in the correct order to replicate the results
in the paper. The script exhibits.R then produces the final tables and figures.

Prerequisites:
  - Stata 17+ with reghdfe, ftools installed
  - R with data.table, ggplot2, textab, readstata13
  - Raw admin data in data/admin/raw/
    (see external_inputs.txt for the full list)
  - O*NET crosswalk: run match_industry_to_occ.py and occ_crosswalk.R
    before Part 3 (see data_construction/ for details)
	
Note: this replication package is written as if the administrative files
are contained in data/admin/raw. In practice, these files will be on servers
maintained by Statistics Norway, and all analyses would be done on these
servers.

*/

* --- Project root (update this path for your environment) ---
global root "/path/to/replication"

ssc install reghdfe
ssc install ftools

** =========================================================
** Input datasets
** =========================================================
/*
The do-files below call the following datasets, which are generated
starting from the raw files of the Norwegian administrative registers.
The construction scripts are included in code/admin/archive/ for
reference.

  data/admin/raw/bs9519.dta
    Firm balance sheet data, 1995-2019 (revenues, costs, profits,
    assets, employment, NACE codes, founding dates).

  data/admin/raw/ee_extended_9518.dta
    Employer-employee register, 1995-2018 (wages, hours, occupation,
    industry, municipality). Person-level.

  data/admin/raw/ee_extended_9518_lfirm.dta
    Employer-employee register collapsed to the person-firm-year level.

  data/admin/raw/founding_dates.dta
    Firm founding dates derived from the business register and
    balance sheet records.

  data/admin/raw/firm_ownership_01_19.dta
    Firm ownership panel, 2001-2019. Identifies individuals and families
    owning a controlling interest in private non-financial limited
    liability companies (ownership shares, sector, industry, firm age).
*/

** =========================================================
** Part 1: Data construction
** =========================================================

* Identify births and link to parents
do "$root/code/admin/data_construction/identify_births.do"

* Identify proximity to parents (newborns' grandparents)
do "$root/code/admin/data_construction/grandparent_location.do"

** =========================================================
** Part 2: Panel construction
** =========================================================

* Main analysis panel (1/3+ ownership threshold)
do "$root/code/admin/data_construction/setup_panel.do" 33

* Robustness panel (1/4+ ownership threshold, for robustness.do)
do "$root/code/admin/data_construction/setup_panel.do" 25

** =========================================================
** Part 3: Analysis
** =========================================================

* Summary statistics (Table 1)
do "$root/code/admin/analysis/summary_stats.do"

* Main event study estimates (Figures 1-3, Tables 2-3, Figure A1)
do "$root/code/admin/analysis/estimation_main.do"

* Heterogeneity by entrepreneur ability (Figures 2, A2)
do "$root/code/admin/analysis/event_study_ability.do"

* Heterogeneity by entrepreneur/firm characteristics (Tables A3, A4)
do "$root/code/admin/analysis/estimation_heterogeneity.do"

** =========================================================
** Part 4: Robustness
** =========================================================

* Alternative sample/control definitions (Table A5) and trimming thresholds (Table A6)
do "$root/code/admin/analysis/robustness.do"

* Wage response for non-entrepreneurs (Figure A3)
do "$root/code/admin/analysis/wage_penalty.do"

** =========================================================
** Part 5: Time-use analysis using EU-SILC (Figures 3, A4)
** =========================================================

* Clean EU-SILC microdata (must run before analysis.do)
do "$root/code/silc/cleaning_P_vars.do"
do "$root/code/silc/cleaning_R_vars.do"
do "$root/code/silc/cleaning_h_vars.do"

* EU-SILC regressions (Figures 3, A4; Table A6)
do "$root/code/silc/analysis.do"
